package com.googlecode.jyoutubeuploader.controller;

import org.apache.log4j.Logger;

import com.googlecode.jyoutubeuploader.parser.ArgumentMapper;
import com.googlecode.jyoutubeuploader.parser.CommandLineParser;
import com.googlecode.jyoutubeuploader.to.YouTubeArgumentsTo;
import com.googlecode.jyoutubeuploader.uploader.Uploader;

/**
 * @author tom
 *
 *	The main controller for the application.
 */
public final class JYoutubeUploader {

	private static final String WELCOME_MESSAGE = "Welcome to j-youtube-uploader...";

	private Logger logger;
	private CommandLineParser commandLineParserService;
	private ArgumentMapper argumentMapper;
	private Uploader uploader;
	
	private String[] args;

	/**
	 * 	Main controller method, it orchestrates the whole process.
	 * @param args 
	 */
	public final void launchApp(String[] args) {
		this.args = args;
		displayMessage(WELCOME_MESSAGE);
		validateArguments();
		mapArguments();
		doUpload();
	}

	private void validateArguments() {
		commandLineParserService.printAllArguments();
		commandLineParserService.validateArguments();
	}

	private void mapArguments() {
		YouTubeArgumentsTo ytArgs = argumentMapper.mapArguments();
		uploader.setArgs(ytArgs);
	}

	private void doUpload() {
		uploader.doUpload();
	}

	private void displayMessage(String message) {
		logger.info(message);
	}

	public void setLogger(Logger logger) {this.logger = logger;}
	public void setCommandLineParserService(CommandLineParser commandLineParserService) {this.commandLineParserService = commandLineParserService;}
	public void setArgumentMapper(ArgumentMapper argumentMapper) {this.argumentMapper = argumentMapper;}
	public void setUploader(Uploader uploader) {this.uploader = uploader;}
}
